int TOPX = 25;
int TOPY = 25;
int LENX=200;
int LENY=200;
int WIDTHX=25;
int WIDTHY=25;

int OFFCOLOR=195;
int NUMPANELS=16;

LedMatrix[] led;
LedMatrix c_led;

boolean c_sw = false;
int pX, pY;

void setup(){
  int i,j;
  background(51);
  size(250,250);
  stroke(255);
  fill(0);
  rect(TOPX,TOPY,LENX,LENY);
  stroke(195);
  for (i=1 ; i < 8 ; i++){
    line(TOPX,TOPY+WIDTHY*i,TOPX+WIDTHX*8,TOPY+WIDTHY*i);
    line(TOPX+WIDTHX*i,TOPY,TOPX+WIDTHX*i,TOPY+WIDTHY*8);
  }
  noStroke();
  for (i=0 ; i < 8 ; i++){
    for (j=0 ; j < 8 ; j++){
      fill(OFFCOLOR);
      ellipse(TOPX + WIDTHX*i + WIDTHX/2, TOPY + WIDTHY * j +WIDTHY/2, 20,20);
    }
  }
  
  led= new LedMatrix[NUMPANELS];
  
  led[0] = new LedMatrix();
  c_led = led[0];
    
}
void draw(){


}
void mousePressed(){
    if (mouseX > TOPX  && mouseX < TOPX+LENX && mouseY > TOPY && mouseY < TOPY + LENY){
      pX =floor (map( mouseX-TOPX,0,200,0,8));
      pY= floor (map( mouseY-TOPY,0,200,0,8));
      // debug
      println(" Mouse : " + mouseX + " " + mouseY + " Mapped :" + pX + " " +pY);

      // invert off/on
      c_led.setStats(pX, pY, !c_led.getStats(pX, pY));
      
      if ( c_led.getStats(pX, pY) )  // is ture
      {
        noStroke();
        fill(255,0,0);
        ellipse(TOPX + WIDTHX*pX + WIDTHX/2, TOPY + WIDTHY * pY +WIDTHY/2, 20,20);
      } else {
        noStroke();
        fill(OFFCOLOR);
        ellipse(TOPX + WIDTHX*pX + WIDTHX/2, TOPY + WIDTHY * pY +WIDTHY/2, 20,20);
      }

      
    }
}


class LedMatrix {
  boolean[][] stats = new boolean[8][8];
  
  // Constructor
  LedMatrix(){
    int i,j;
    for (i=0 ; i < 8 ; i++){
      for (j=0 ; j < 8 ; j++){
        stats[i][j]=false;
      }
    }

  }
  
  boolean getStats(int x, int y){
    return stats[x][y];
  }

  void setStats(int x, int y, boolean val){
    stats[x][y] = val;
  }

  void on(int x, int y){
     stats[x][y] = true;
  }

  void off(int x, int y){
     stats[x][y] = false;
  }

}

